package hardcode2013;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ItemProfile {
	private String keyStr;
	private String title;
	private String description;
	private String price;
	private String creationDateTime; //yyyy-MM-dd HH:mm
	private String seller;
	private String expirationDateTime; //yyyy-MM-dd HH:mm
	
	public ItemProfile(String keyStr, String title, String description, String price, String creationDateTime, String seller, String expirationDateTime) {
		this.keyStr = keyStr;
		this.title = title;
		this.description = description;
		this.price = price;
		this.creationDateTime = creationDateTime;
		this.seller = seller;
		this.expirationDateTime = expirationDateTime;
	}
	
	public boolean isExpired() {
		try {
			Date exTime = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(expirationDateTime);
			Date today = new Date();
			return (! today.before(exTime));
		} catch (Exception e) {
			return true;
		}
	}
	
	public String getKeyStr() {return keyStr;}
	public String getTitle() {return title;}
	public String getDescription() {return description;}
	public String getPrice() {return price;}
	public String getCreationDateTime() {return creationDateTime;}
	public String getCreationDateOnly() {return creationDateTime.substring(0, creationDateTime.indexOf(" "));}
	public String getCreationTimeOnly() {return creationDateTime.substring(creationDateTime.indexOf(" ") + 1);}
	public String getSeller() {return seller;}
	public String getExpirationDateTime() {return expirationDateTime;}
	public String getExpirationDateOnly() {return expirationDateTime.substring(0, creationDateTime.indexOf(" "));}
	public String getExpirationTimeOnly() {return expirationDateTime.substring(creationDateTime.indexOf(" ") + 1);}
	
	public void setKeyStr(String keyStr) {this.keyStr = keyStr;}
	public void setTitle(String title) {this.title = title;}
	public void setDescription(String description) {this.description = description;}
	public void setPrice(String price) {this.price = price;}
	public void setCreationDateTime(String creationDateTime) {this.creationDateTime = creationDateTime;}
	public void setSeller(String seller) {this.seller = seller;}
	public void setExpirationDateTime(String expirationDateTime) {this.expirationDateTime = expirationDateTime;}
}
